package com.atguigu.myjuc.mythread;

import java.util.concurrent.locks.ReentrantLock;

public class LockThread {
    public static final ReentrantLock lock = new ReentrantLock();
 static class ticket {
     int number = 50;

     public void saleTicket() {
         lock.lock();
         if (number > 0) {
             try {
                 System.out.println(Thread.currentThread().getName() + "当前有" + number + "还剩下" + --number);
             } finally {
                 lock.unlock();
             }
         }
     }
 }
    public static void main(String[] args) {
        ticket ticket = new ticket();
        new Thread(()->{for (int i = 0; i < 50; i++) ticket.saleTicket();},"a").start();
        new Thread(()->{for (int i = 0; i < 50; i++) ticket.saleTicket();},"b").start();
        new Thread(()->{for (int i = 0; i < 50; i++) ticket.saleTicket();},"c").start();
   }
    }
